// eslint-disable-next-line no-undef
const path = require("path");

// eslint-disable-next-line no-undef
const { defineConfig } = require("@vue/cli-service");
// eslint-disable-next-line no-undef
const { chainWebpackPlugins } = require("./webpack/plugins");
// eslint-disable-next-line no-undef
const devServer = require("./webpack/config/devServer");

function resolve(dir) {
  // eslint-disable-next-line no-undef
  return path.join(__dirname, ".", dir);
}

// eslint-disable-next-line no-undef
module.exports = defineConfig({
  // eslint-disable-next-line no-undef
  publicPath: process.env["VUE_APP_PUBLIC_PATH"],
  transpileDependencies: true,
  devServer,
  configureWebpack: {
    // eslint-disable-next-line no-undef
    plugins: chainWebpackPlugins(process.env)
  },
  chainWebpack: config => {
    config.module.rules.delete("svg"); // 重点：删除默认配置中处理svg,
    config.module
      .rule("svg-sprite-loader")
      .test(/\.svg$/)
      .include.add(resolve("src/assets/images/svg")) // 处理svg目录
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        symbolId: "icon-[name]"
      });
  }
});
